package com.example.generate_code.utils;

import com.example.generate_code.model.Db;

import java.sql.Connection;
import java.sql.DriverManager;

/**
 * @ClassName DBUtils
 * @Description
 * @Author zhangsw
 * @Date 2021/1/5 21:38
 * @Version 1.0
 */
public class DBUtils {

    private static Connection connection;

    public static Connection initDB(Db db) {
        if (connection == null) {
            try {
                Class.forName("com.mysql.cj.jdbc.Driver");
                connection = DriverManager.getConnection(db.getUrl(), db.getUsername(), db.getPassword());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return connection;
    }
}
